include(ExternalProject)
if (NOT ENABLE_NNDEPLOY_INFERENCE_RKNN_TOOLKIT_1 STREQUAL "OFF")
  if (NOT ENABLE_NNDEPLOY_INFERENCE_RKNN_TOOLKIT_2 STREQUAL "OFF")
    message(FATAL_ERROR "Both rknn_toolkit_1 and rknn_toolkit_2 are enabled, please choose one of them.")
  else()
    message(STATUS "using rknn_toolkit_1")
    add_definitions(-DRKNN_TOOLKIT_1)
    set(ENABLE_NNDEPLOY_INFERENCE_RKNN ${ENABLE_NNDEPLOY_INFERENCE_RKNN_TOOLKIT_1})
  endif()
endif()

if (NOT ENABLE_NNDEPLOY_INFERENCE_RKNN_TOOLKIT_2 STREQUAL "OFF")
    message(STATUS "using rknn_toolkit_2")
    add_definitions(-DRKNN_TOOLKIT_2)
    set(ENABLE_NNDEPLOY_INFERENCE_RKNN ${ENABLE_NNDEPLOY_INFERENCE_RKNN_TOOLKIT_2})
endif()

if (NOT DEFINED ENABLE_NNDEPLOY_INFERENCE_RKNN)
else()
  include_directories(${ENABLE_NNDEPLOY_INFERENCE_RKNN}/include)
  set(LIB_PATH ${ENABLE_NNDEPLOY_INFERENCE_RKNN}/${NNDEPLOY_THIRD_PARTY_LIBRARY_PATH_SUFFIX})
  set(LIBS "rknn_api")
  foreach(LIB ${LIBS})
    set(LIB_NAME ${NNDEPLOY_LIB_PREFIX}${LIB}${NNDEPLOY_LIB_SUFFIX})
    set(FULL_LIB_NAME ${LIB_PATH}/${LIB_NAME})
    if(IS_SYMLINK ${FULL_LIB_NAME})
      get_filename_component(REAL_LIB_NAME ${FULL_LIB_NAME} REALPATH)
      # message(STATUS "Real path of ${FULL_LIB_NAME}: ${REAL_LIB_NAME}")
      set(FULL_LIB_NAME ${REAL_LIB_NAME})
      # message(STATUS "Full lib name: ${FULL_LIB_NAME}")
    endif()
    set(NNDEPLOY_THIRD_PARTY_LIBRARY ${NNDEPLOY_THIRD_PARTY_LIBRARY} ${FULL_LIB_NAME})    
  endforeach()
  # file(GLOB_RECURSE INSTALL_LIBS "${LIB_PATH}/*")
  # foreach(INSTALL_LIB ${INSTALL_LIBS})
  #   install(FILES ${INSTALL_LIB} DESTINATION ${NNDEPLOY_INSTALL_LIB_PATH})
  # endforeach()
  install(DIRECTORY ${ENABLE_NNDEPLOY_INFERENCE_RKNN} DESTINATION ${NNDEPLOY_INSTALL_THIRD_PARTY_PATH})
endif()